#include <iostream>
#include <string>
using namespace std;
int main(){
	int code,id,score;
	char ch;
	int a[1001]={0};
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>code>>ch>>id>>score;
		a[code]+=score;
	}
	int max=-1,index=-1;
	for(int j=0;j<1001;j++){
		if(a[j]>max){
			max=a[j];
			index=j;
		}
	}
	cout<<index<<" "<<max<<endl;
}
